Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var addCurrencyStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=Currency',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
	}); 

	var addDebtTypeLevelOneStore=new Ext.data.Store({
		proxy:new Ext.data.HttpProxy({
			url:'showDebtTypeLevelOne.do',
			method:'GET'
		}),
		reader:new Ext.data.JsonReader({},[{name:'name'},{name:'code'}]),
		autoLoad:true
	});

	var addDebtTypeLevelTwoStore=new Ext.data.Store({
		reader:new Ext.data.JsonReader({},[{name:'name'},{name:'code'}]),
	});

	var addBusinessKindStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=BusinessKind',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) 
	,
	autoLoad:true
	}); 

	var addBusinessStyleStore=new Ext.data.Store({ 
		proxy:new Ext.data.HttpProxy({
		url:'showType.do?type=BusinessStyle',
		method:'GET'
		}), 
		reader:new Ext.data.JsonReader({ },[
		{name:'name'}, 
		{name:'code'}
		]) 
		,
		autoLoad:true
		}); 

	var addGuarantyKindStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=GuarantyKind',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
	}); 

	var pInterestTypeStore=new Ext.data.Store({ 
		proxy:new Ext.data.HttpProxy({
		url:'showType.do?type=PInterestType',
		method:'GET'
		}), 
		reader:new Ext.data.JsonReader({ },[
		{name:'name'}, 
		{name:'code'}
		]) ,
		autoLoad:true
		}); 

	var yesOrNoStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=YesNo',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
	}); 

	var addInterestCycleStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=InterestCycleType',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
	}); 

	var addNationalityStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=CountryCode',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
	}); 

	var classifyResultStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=ClassifyResult',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]),
	autoLoad:true
	}); 


	//债项详情
	var addForm = new Ext.form.FormPanel({ 
	id: 'addForm', 
	title:'债项信息',
	renderTo:"list",
	height: 520, 
	//样式 
	bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
	frame: true, 
	xtype: 'filedset', 
	labelWidth: 100, 
	items: 
	[ { xtype: 'fieldset',  
	collapsible: true, 
	autoHeight: true, 
	autoWidth: true, 
	items: 
	[
	{layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
		       		id:'debtId',
		       		name: 'debtId', 
		       		fieldLabel: '债项编号', 
		       		emptyText: '必填', 
		       		blankText: '债项编号不能为空', 
		       		allowBlank: false, 
		       		width: 200
		        	
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
		       		id:'debtDesc',
		       		name: 'debtDesc', 
		       		fieldLabel: '债项名称', 
		       		emptyText: '必填', 
		       		blankText: '债项名称不能为空', 
		       		allowBlank: false, 
		       		width: 200
	
	}
	]} 
	]},
	{layout:"column",
		items:[{
		columnWidth : .5, // 该列有整行中所占百分比	
		layout : "form",
		items : [{
			xtype: 'combo', 
			id : "debtTypeLevelOne",
			store :addDebtTypeLevelOneStore,
			fieldLabel: '债项业务品种大类',
			valueField : 'code',
			displayField : 'name',
			typeAhead : true,
			width: 200,
			mode:'remote', 
			emptyText : '请选择债项业务品种大类...',
			blankText: '债项大类不能为空', 
			allowBlank: false, 
			editable: false,
			triggerAction : 'all',
			selectOnFocus : true,
			hiddenName:'debtTypeLevelOne',
			listeners:{
				select:function(combo,record,index)
				{
					var levelTwoCombo = Ext.getCmp('debtType');
					levelTwoCombo.clearValue();
					addDebtTypeLevelTwoStore.proxy = new Ext.data.HttpProxy({
						url:'showDebtTypeLevelTwo.do?levelOneCode=' + combo.value,
						method:'GET'
					});
					addDebtTypeLevelTwoStore.reload();
				}
			}
		}]}
		,{
			columnWidth : .5, // 该列有整行中所占百分比	
			layout : "form",
			items : [{
				
		}
		]}
	]},
	{layout : "form",
		items : [{
			xtype: 'combo', 
			id : "debtType",
			store :addDebtTypeLevelTwoStore,
			fieldLabel: '债项业务品种子类',
			blankText: '债项子类不能为空', 
			allowBlank: false, 
			valueField : 'code',
			displayField : 'name',
			typeAhead : true,
			width: 380,
			mode:'remote', 
			emptyText : '请选择债项业务品种子类...',
			editable: false,
			triggerAction : 'all',
			selectOnFocus : true,
			hiddenName:'debtType',
		}]},	
	{layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
	        layout : "form",
	        items : [{
	        	xtype: 'textfield',
	        	id: 'debtContractNo', 
	        	name: 'debtContractNo', 
	        	fieldLabel: '借款合同编号',
	        	editable: true,  
	        	width: 200 
	        }]
	    },{ 
	        columnWidth : .5, // 该列有整行中所占百分比
	        layout : "form",
	        items : [{
	        	xtype: 'textfield',
	        	id: 'loanNo', 
	        	name: 'loanNo', 
	        	fieldLabel: '借据编号',
	        	editable: true, 
	        	width: 200 
	        }]
	   }]
	},{
	layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	xtype: 'textfield', 
		id: 'debtSum',
		name: 'debtSum', 
		fieldLabel: '合同金额（元）', 
		emptyText: '必填', 
		blankText: '合同金额不能为空', 
		allowBlank: false,  
		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
	 	regexText:'只能输入整数或小数！' , 
		width: 200
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
		xtype: 'combo', 
	 	id : "currency",
	              store :addCurrencyStore,
	              fieldLabel: '债项币种',
	              valueField : 'code',
	              displayField : 'name',
	              typeAhead : true,
	              width: 200,
	              mode:'remote', 
	              emptyText : '请选择币种...',
	              editable: false,
	              triggerAction : 'all',
	              selectOnFocus : true,
	              hiddenName:'currency'
	}
	]} 
	]},{
		layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
		           layout : "form",
		           items : [{
			       		xtype: 'textfield', 
			    		id: 'debtBalance',
			    		name: 'debtBalance', 
			    		fieldLabel: '信贷余额（元）', 
			    		emptyText: '必填', 
			    		blankText: '信贷余额不能为空', 
			    		allowBlank: false,  
			    		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
			    	 	regexText:'只能输入整数或小数！' , 
			    		width: 200
		}
		]},{
			columnWidth : .5, // 该列有整行中所占百分比
		           layout : "form",
		           items : [{
			       		xtype: 'textfield', 
			    		id: 'loanSum',
			    		name: 'loanSum', 
			    		fieldLabel: '借据金额（元）', 
			    		emptyText: ' ', 
			    		blankText: ' ', 
			    		allowBlank: true,  
			    		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
			    	 	regexText:'只能输入整数或小数！' , 
			    		width: 200
		}
		]} 
		]},
	{
	layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	           xtype: 'datefield',
	id: 'startDate', 
	name: 'startDate', 
	fieldLabel: '起始日',
	allowBlank: true,
	editable:false,  
	format : 'Y-m-d' ,
	width: 200
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	           xtype: 'datefield',
	id: 'endDate', 
	name: 'endDate', 
	fieldLabel: '到期日',
	allowBlank: true,
	editable:false,  
	format : 'Y-m-d' ,
	width: 200
	}
	]} 
	]},

	{
		layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
			layout : "form",
			items : [	{ 
				  xtype: 'combo', 
				  id : "businessKind",
			      store :addBusinessKindStore,
			      fieldLabel: '授信类型',
			      valueField : 'code',
			      displayField : 'name',
			      typeAhead : true,
			      width: 200,
			      mode:'remote', 
			      emptyText : '请选择授信类型...',
			      editable: false,
			      triggerAction : 'all',
			      selectOnFocus : true,
			      hiddenName:'businessKind'
			}]},{
			columnWidth : .5, // 该列有整行中所占百分比
			layout : "form",
			items : [	{ 
				  xtype: 'combo', 
				  id : "isCycle",
			      store :yesOrNoStore,
			      fieldLabel: '是否循环授信',
			      valueField : 'code',
			      displayField : 'name',
			      typeAhead : true,
			      width: 200,
			      mode:'remote', 
			      emptyText : '请选择是否...',
			      editable: false,
			      triggerAction : 'all',
			      selectOnFocus : true,
			      hiddenName:'isCycle',
			      hidden:true,
			}]} 
		]},

		{
			layout:"column",
			items:[{
				columnWidth : .5, // 该列有整行中所占百分比
				layout : "form",
				items : [	{ 
					  xtype: 'combo', 
					  id : "businessStyle",
				      store :addBusinessStyleStore,
				      fieldLabel: '授信形式',
				      valueField : 'code',
				      displayField : 'name',
				      typeAhead : true,
				      width: 200,
				      mode:'remote', 
				      emptyText : '请选择授信形式...',
				      editable: false,
				      triggerAction : 'all',
				      selectOnFocus : true,
				      hiddenName:'businessStyle'
				}]},{
				columnWidth : .5, // 该列有整行中所占百分比
				layout : "form",
				items : [	{ 
					  xtype: 'combo', 
					  id : "guarantyKind",
		              store :addGuarantyKindStore,
		              fieldLabel: '担保类型',
		              valueField : 'code',
		              displayField : 'name',
		              emptyText : '请选择担保类型...',
		              editable: false,
		              typeAhead : true,
		              width: 200,
		              mode:'remote',  
		              triggerAction : 'all',
		              selectOnFocus : true,
		              hiddenName:'guarantyKind'
				}]} 
			]},

	{layout : "form",
		items : [	{ 
	xtype: 'combo', 
	 id : "groupLoanType",
	              store :yesOrNoStore,
	              fieldLabel: '是否是银团贷款',
	              valueField : 'code',
	              displayField : 'name',
	              typeAhead : true,
	              width: 200,
	              mode:'remote', 
	              emptyText : '请选择是否为银团贷款...',
	              editable: false,
	              triggerAction : 'all',
	              selectOnFocus : true,
	              hiddenName:'groupLoanType'
		}]},	

	{layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
			layout : "form",
	        items : [{
	        	xtype: 'textfield', 
				id: 'interestSum',
				name: 'interestSum', 
				fieldLabel: '利息总额（元）', 
				width:200,
				regex:/^[0-9]+(.[0-9]{0,5})?$/,
			 	regexText:'只能输入整数或5位小数！' , 
		      
	}]},{
	    	columnWidth : .5, // 该列有整行中所占百分比
	    	layout : "form",
	        items : [{
	     	   xtype: 'combo', 
	     	   id : "interestCycle",
	           store :addInterestCycleStore,
	           fieldLabel: '计息周期',
	           valueField : 'code',
	           displayField : 'name',
	           typeAhead : true,
	           width: 200,
	           mode:'remote', 
	           emptyText : '请选择计息周期...',
	           editable: false,
	           triggerAction : 'all',
	           selectOnFocus : true,
	           hiddenName:'interestCycle'
	           
	}]} 
	]},


	{layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
			layout : "form",
	        items : [{
	        	xtype: 'textfield', 
				id: 'interestRate',
				name: 'interestRate', 
				fieldLabel: '利率值（%）', 
				width: 200,	
				regex:/^[0-9]+(.[0-9]{0,5})?$/,
			 	regexText:'只能输入整数或5位小数！' , 
	           
	}]},{
	    	columnWidth : .5, // 该列有整行中所占百分比
	    	layout : "form",
	        items : [{
	        	xtype: 'textfield', 
				id: 'interestRateCode',
				name: 'interestRateCode', 
				fieldLabel: '利率代码', 
				width: 200 
	           
	}]} 
	]},


	{layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
	        layout : "form",
	        items : [{
	        	xtype: 'textfield', 
				id: 'pinterestRate',
				name: 'pinterestRate', 
				fieldLabel: '罚息利率值（%）', 
				width: 200,	
				regex:/^[0-9]+(.[0-9]{0,5})?$/,
			 	regexText:'只能输入整数或5位小数！' ,
				}
	    ]},{
	    	columnWidth : .5, // 该列有整行中所占百分比
	    	layout : "form",
	    	items : [{
	    		xtype: 'combo', 
	     	   id : "pinterestType",
	           store :pInterestTypeStore,
	           fieldLabel: '罚息利率类型',
	           valueField : 'code',
	           displayField : 'name',
	           typeAhead : true,
	           width: 200,
	           mode:'remote', 
	           emptyText : '请选择罚息利率类型...',
	           editable: false,
	           triggerAction : 'all',
	           selectOnFocus : true,
	           hiddenName:'pinterestType',
	        	  
	    	   }
	    ]} 
	]},
	{layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
			layout : "form",
	        items : [{
	        	xtype: 'textfield', 
				id: 'pinterestRateCode',
				name: 'pinterestRateCode', 
				fieldLabel: '罚息利率代码', 
				blankText: '罚息利率代码不能为空', 
				width: 200
	           
	}]},{
	    	columnWidth : .5, // 该列有整行中所占百分比
	    	layout : "form",
	    	items : [{
	    	   xtype: 'textfield', 
	    	   id : "marginRate",
	    	   fieldLabel: '保证金比例(%)',
	    	   width: 200,
	    	   hiddenName:'marginRate',	
				regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
			 	regexText:'只能输入整数或小数！' , 
	    	   }
	    ]} 
	]},
	{layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
			layout : "form",
	        items : [{
	        	xtype: 'textfield', 
				id: 'collateralRate',
				name: 'collateralRate', 
				fieldLabel: '抵质押率（%）', 
				regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
			 	regexText:'只能输入整数或小数！' , 
				blankText: ' ', 
				width: 200
	           
	}]},{
	    	columnWidth : .5, // 该列有整行中所占百分比
	    	layout : "form",
	    	items : [{
	    	   xtype: 'textfield', 
	    	   id : "guarantorNum",
	    	   fieldLabel: '保证人个数',
	    	   width: 200,
	    	   hiddenName:'guarantorNum',	
				regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
			 	regexText:'只能输入整数 ！' , 
	    	   }
	    ]} 
	]},
	{layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
			layout : "form",
	        items : [{
	        	xtype: 'textfield', 
				id: 'collateralTypeNum',
				name: 'collateralTypeNum', 
				fieldLabel: '同一借据下抵质押品种类数', 
				regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
			 	regexText:'只能输入整数！' , 
				blankText: ' ', 
				width: 200
	           
	}]},{
	    	columnWidth : .5, // 该列有整行中所占百分比
	    	layout : "form",
	    	items : [{
	    	   }
	    ]} 
	]}


	] 
	}],
	buttonAlign:'right',
	buttons: 
	[  

	{ text: '保存', handler: editFunction },
	{ text: '下一步', handler: editFunctionAndNext } 
	] 
	});

//表单加载数据 新增页面不加载
//addForm.form.load({  
//    waitMsg : '正在加载数据请稍后',
//    waitTitle : '提示',
//    url : 'obligation/getDebtInfo.do', 
//    method:'post',
//    success:function(form,action){
//    	
//    },  
//    failure:function(form,action){
//     Ext.Msg.alert('提示','数据加载失败');  
//    }  
//});

function editFunction(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'obligation/addDebt.do', 
			method : 'post', 
			success : function() {
				Ext.Msg.alert('提示', '保存成功！'); 
				window.location.href = "view/obligation/DebtInfoDetail.jsp";
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '保存失败！'); 
			} 
		}); 
	}
	
}

function editFunctionAndNext(){
	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'obligation/addDebt.do', 
			method : 'post', 
			success : function() {
				Ext.Msg.confirm("Confirm",'保存成功！<br>是否继续添加风险缓释信息?',function(bool){
					if(bool=='yes'){
						window.location.href = "view/obligation/DebtGuaranteeInfo.jsp";
						return true;
					}
					else{
						return false;	
					}
				}); 
				//alert("成功");
				
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '新增失败！'); 
			} 
		}); 
	}
}
       
}); 